﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WpfApp1.Models;
using WpfApp1.Servcies;

namespace WpfApp1
{
    /// <summary>
    /// TreeViewDemo2.xaml 的交互逻辑
    /// </summary>
    public partial class TreeViewDemo2 : Window
    {
        //ObservableCollection<Dept> depts;
        List<Dept> depts;

        public TreeViewDemo2()
        {
            InitializeComponent();

            // depts = new ObservableCollection<Dept>(DeptService.ListTree());
            depts = DeptService.ListTree();

            treeView1.ItemsSource = depts;
        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            Button button = (Button)sender;

            if (button.Name == "btnAdd")
            {
                Dept old = depts.First(m => m.Id == 3);
                old.SubDepts.Add(new Dept(10, "test", 3));
            }
            else if (button.Name == "btnUpdate")
            {
                Dept old = depts.First(m => m.Id == 2);
                old.Name = "_";
            }
            else if (button.Name == "btnDelete")
            {
            }
            else if (button.Name == "btnRebinding")
            {
                treeView1.ItemsSource = null;
                treeView1.ItemsSource = depts;
            }
        }
    }
}
